﻿
<!--_meta 作为公共模版分离出去-->
{include file="public/_meta"}

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 角色列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<form action="" method="get">
		<div class="text-c">
			<input type="text" class="input-text" style="width:250px" placeholder="输入角色名" id="" name="keywords">
			<button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜角色</button>
		</div>
	</form>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="dataDel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a href="javascript:;" onclick="add_role('添加角色','{:url(\'role/add_role\')}','800','400')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加角色</a></span> <span class="r">共有数据：<strong>{$count}</strong> 条</span> </div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-hover table-bg table-sort">
			<thead>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="80">ID</th>
				<th width="50">角色名</th>
				<th width="90">角色权限</th>
				<th width="70">状态</th>
				<th width="100">操作</th>
			</tr>
			</thead>
			<tbody>
			{volist name="roles" id="vo"}
			<tr class="text-c">
				<td><input type="checkbox" value="{$vo.id}" name="id[]"></td>
				<td>{$vo.id}</td>
				<td><a href="javascript:void(0);" style="cursor:pointer" class="text-primary" onclick="role_show('{$vo.title}','{:url(\'role/role_show\')}?id={$vo.id}','{$vo.id}','360','400')"><u><b>{$vo.title}</b></u></a></td>
				<td>{$vo.rules|mb_substr=0,11,'utf-8'}...</td>
				<td class="td-status">
					{if condition="$vo.stop_status eq 1"}
					<span class="label label-success radius">已启用</span>
					{else/}
					<span class="label label-defaunt radius">已停用</span>
					{/if}
				</td>
				<td class="td-manage">{if condition="$vo.stop_status eq 1"}<a style="text-decoration:none" onClick="stop_role(this,'{$vo.id}')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>{else/}<a style="text-decoration:none" onClick="start_role(this,'{$vo.id}')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>{/if} <a title="编辑" href="javascript:;" onclick="edit_role('编辑','{:url(\'role/edit_role\')}?id={$vo.id}','{$vo.id}','800','400')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="del_role(this,'{$vo.id}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
			</tr>
			{/volist}
			</tbody>
		</table>
	</div>
</div>

<!--_footer 作为公共模版分离出去-->
{include file="public/_footer"}

<script type="text/javascript">
	$(function(){
		$('.table-sort').dataTable({
			"aaSorting": [[ 1, "asc" ]],//默认第几个排序
			"bStateSave": true,//状态保存
			"aoColumnDefs": [
				{"orderable":false,"aTargets":[0,5]}// 制定列不参与排序
			]
		});
	});
	/*用户-添加*/
	function add_role(title,url,w,h){
		layer_show(title,url,w,h);
	}
	/*用户-查看*/
	function role_show(title,url,id,w,h){
		layer_show(title,url,w,h);
	}
	/*停用角色*/
	function stop_role(obj,id){
		layer.confirm('确认要停用吗？',function(){
			$.ajax({
				type: 'post',
				url: "{:url('role/stop_role_ajax')}",
				dataType: 'json',
				data: {id:id},
				success: function(msg){
					if(msg.status == true){
						layer.msg(msg.message,{icon: 6,time:1000});
						setTimeout(jump,1000);
						function jump(){
							window.location.replace(location.href);
						}
					}else if(msg.status == false){
						layer.msg(msg.message,{icon: 5,time:1000});
					}
				},
				error:function(msg) {
					console.log(msg.msg);
				}
			});
		});
	}

	/*启用角色*/
	function start_role(obj,id){
		layer.confirm('确认要启用吗？',function(){
			$.ajax({
				type: 'POST',
				url: "{:url('role/start_role_ajax')}",
				dataType: 'json',
				data: {id:id},
				success: function(data){
					if(data == true){
						layer.msg('已启用!',{icon: 6,time:1000});
						setTimeout(jump,1000);
						function jump(){
							window.location.replace(location.href);
						}
					}else if(data == false){
						layer.msg('启用失败!',{icon: 5,time:1000});
					}
				},
				error:function(data) {
					console.log(data.msg);
				},
			});
		});
	}
	/*角色编辑-编辑*/
	function edit_role(title,url,id,w,h){
		layer_show(title,url,w,h);
	}
	/*密码-修改*/
	function change_password(title,url,id,w,h){
		layer_show(title,url,w,h);
	}
	/*角色-删除*/
	function del_role(obj,id){
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				type: 'get',
				url: "{:url('role/del_role')}",
				dataType: 'json',
				data: {id:id},
				success: function(msg){
					if(msg.status == true){
						$(obj).parents("tr").remove();
						layer.msg('删除角色成功!',{icon:6,time:1000});
					}else if(msg.status == false){
						layer.msg('删除角色成功!',{icon:5,time:1000});
					}
				},
				error:function(msg) {
					console.log(msg.msg);
				}
			});
		});
	}

	//批量删除
	function dataDel(){
		layer.confirm('确认要删除吗？',function(){
			var role_id =[];
			$('input[name="id[]"]:checked').each(function(){
				role_id.push($(this).val());
			});
			$.ajax({
				type: 'post',
				url: "{:url('role/batch_del_role')}",
				dataType: 'json',
				data: {id:role_id},
				success: function(msg){
					if(msg.status == true){
						layer.msg(msg.message,{icon:6,time:1000});
						setTimeout(jump,1000);
						function jump(){
							window.location.reload();
						}
					}else if(msg.status == false){
						layer.msg(msg.message,{icon:5,time:1000});
					}
				}
			});
		});
	}
</script>
